<template>
	<view class="container">
		<head >
			<view class="top">
				<view class="left">
					<p>
						<text>第{{leave}}级</text>
						<text>题库{{questionInfo.bankId}}</text>
					</p>
					<!-- <view class="example-body t">
						<uni-countdown :show-day="false" :hour="00" :minute="01" :second="00" @timeup="timeup" />
					</view> -->
					<!-- <p class="t">
						<text>00:08:38</text>
					</p> -->
				</view>
				<view class="right">
					<p><text class="l">{{questionInfo.current+1}}</text>/<text>{{questionInfo.questionNums}}</text></p>
				</view>
			</view>
			<view class="uni-title uni-common-mt uni-common-pl" style="font-size: 14px;">
				{{questionInfo.current+1}}.{{questionInfo.questionStem}}</view>
			<view class="uni-list">
				<checkbox-group @change="checkboxChange">
					<label v-for="item in questionInfo.optionDtos" :key="index" class="uni-list-cell uni-list-cell-pd" style="display: flex;justify-content: space-between;">
							<view style="font-size: 14px;">{{item.option}}</view>
							<view>
								<checkbox :value="item.option.substring(0,1) " :checked="item.selected==null||0?false:true" />
							</view>
						
					</label>
				</checkbox-group>
			</view>
			
		</head>
		<body>
			<view style="height: 60px;width: 100%;background-color: #CCE6FF;position: fixed;bottom: 0;text-align: center;">
				<button type="default" size="mini" @click="lastone" v-show="flag">上一题</button>
				<!-- <button class="b-s" @click="returnindex" v-show="!flag">返回首页</button> -->
				<button type="default" size="mini" @click="nextone" v-show="flag"><text>下一题</text></button>
				<!-- <button class="b-s" @click="Score" v-show="!flag"><text>交卷</text></button> -->
			</view>
		</body>
	</view>
</template>
<script>
	import {start,next,last} from '../../apis'
	// import uniCountdown from '../../components/uni-countdown/uni-countdown.vue'
	// import uniSection from '../../components/uni-section/uni-section.vue'
	export default {
		data() {
			return {
				// testHour: 0,
				// testMinute: 0,
				// testSecond: 0,
				flag: true,
				questionInfo: {},
				leave: '',
				nextList: {
					answers: '',
					examId: '',
					questionId: ''
				}
			}
		},
		onLoad(option) {
			uni.showLoading({
				title: '加载中'
			});
			this.leave = option.leave
			this.nextList.examId = option.examId
			console.log("examid为：" + this.nextList.examId)
			start({
				"examId": option.examId
			}).then((res) => {
				let [err, data] = res
				this.questionInfo = data.data.data
				uni.hideLoading();
			})
			// setTimeout(() => {
			// 	this.testHour = 1
			// 	this.testMinute = 1
			// 	this.testSecond = 0
			// }, 2000)
		},
		methods: {
			// timeup() {
			// 	this.flag = false
			// 	uni.showToast({
			// 		title: '时间到',
			// 		image:"../../static/gantan.png"
			// 	})
			// },
			checkboxChange(e) {
				// console.log("checkboxChange携带的值为："+ JSON.stringify(e)  )
				this.nextList.answers = e.detail.value.join(',')
				console.log("value值为：" + e.detail.value)
				// e.detail.value = 0
				// console.log("value值为："+e.detail.value)
				// console.log(this.nextList.answers)
			},
			nextone() {
				next({
					"answers": this.nextList.answers,
					"examId": this.nextList.examId,
					"questionId": this.questionInfo.questionId,
				}).then((res) => {
					let [err, data] = res
					if (data.data.code == 200) {
						//this.questionInfo = data.data.data
						//this.flag = true
						console.log('跳转前获取到的题目是')
						console.log(this.questionInfo)
						uni.navigateTo({
							url: '../next/next?questionInfo=' + JSON.stringify(data.data.data) + '&examId=' + this.nextList.examId

						});
					}
					// else{
					// 	this.flag = false
					// 	uni.showToast({
					// 		title: '请求错误'
					// 	});
					// }
				})
			},
			lastone() {
				console.log("上一题")
				console.log(this.nextList.examId)
				last({
					'examId': this.nextList.examId
				}).then((res) => {
					let [err, data] = res
					console.log(data)
					if (data.data.code == 1000114) {
						uni.showToast({
							title: data.data.message,
							duration: 2000,
							image: '../../static/gantan.png'
						});
					}
				})
			}

		}
		// ,
		// Score(){
		// 	console.log("ok")
		// 	result({
		// 		"examId":this.nextList.examId
		// 	}).then((res)=>{
		// 		let [err,data] = res
		// 		console.log("分数为："+data.data.data)
		// 		this.score = data.data.data
		// 		console.log(this.score)
		// 		console.log(typeof this.score)
		// 		uni.showToast({
		// 		    title:  "您的成绩为"+this.score+"分",
		// 		    duration: 5000
		// 			// image:'../../static/chengji.png'
		// 		});
		// 	})

		// },
		// returnindex(){
		// 	uni.switchTab({
		// 		url:'../index/index'
		// 	})
		// }
		// ,
		// components: {
		// 	uniCountdown,
		// 	uniSection
		// }
	}
</script>
<style lang="scss" scoped>
	.container {
		.example-body {
			width: 35%;
			flex-direction: column;
		}

		.word-btn-white {
			font-size: 18px;
			color: #FFFFFF;
		}

		.top {
			display: flex;
			justify-content: space-between;
			padding: 10px;

			// border: 1px solid #007AFF;
			.left {
				text {
					margin-right: 20px;
					font-size: 14px;
				}

				.t {
					margin-top: 5px;
				}
			}

			.right {
				.l {
					font-size: 16px;
				}
			}
		}

		.uni-common-mt {
			margin-top: 0;
		}

		// .btn {
			// display: flex;
			// justify-content: space-between;
			// // width: 100%;
			// button{
			// 	margin-top: 10px;
			// 	background-color: #CCE6FF;
			// 	color: #fff;
			// 	font-weight: bold;
			// 	font-size: 14px;
			// }
			// position: fixed;
			// margin-top: 350px;
			// text-align: center;
			button{
				width: 50%;
				height: 100%;
				text-align: center;
				padding-top: 10px;
				box-shadow: 1px 1px 2px #CCCCCC;
				// margin-right: 60px;
				background-color: #CCE6FF;
				color: #fff;
				font-weight: bold;
				font-size: 18px;
			}
		// }
	}
</style>
